package org.geometerplus.fbreader.bookmodel;

import org.amse.ys.zip.ZipException;
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.zlibrary.core.resources.ZLResource;

import java.io.IOException;

public final class BookReadingException extends Exception {
	/**
	 * 
	 */
    private static final long serialVersionUID = 1L;

	public static void throwForFile(String resourceId, ZLFile file) throws BookReadingException {
		throw new BookReadingException(resourceId, file);
	}

	private static String getResourceText(String resourceId) {
		return ZLResource.resource("bookReadingException").getResource(resourceId).getValue();
	}

	public final ZLFile File;

	public BookReadingException(String resourceId, String param, ZLFile file) {
		super(getResourceText(resourceId).replace("%s", param));
		File = file;
	}

	public BookReadingException(String resourceId, ZLFile file) {
		super(getResourceText(resourceId).replace("%s", file.getPath()));
		File = file;
	}

	public BookReadingException(IOException e, ZLFile file) {
		super(getResourceText(
			e instanceof ZipException ? "errorReadingZip" : "errorReadingFile"
		).replace("%s", file.getPath()), e);
		File = file;
	}
}
